import { floora } from "../compontent/floor-one.js";

import { footmoney, floorlist } from "../compontent/floor-list.js";

import { boxshangpin, rightfloorone } from "../compontent/box-right.js";

Vue.component("floor-one", floora);
Vue.component("floor-list", floorlist);
Vue.component("foot-money", footmoney);
Vue.component("box-shangpin", boxshangpin);
Vue.component("right-floor-one", rightfloorone);

var app = new Vue({
  el: "#app",
  data: {
    order: "noworder",
    menuorder: "commonfoodtext",
    comName: "floor-list",
    dingdanps: 5,
    chanpinps: 7,
    money: 0,
    nowdingdanlist: [],
    yinliaolist: [
      { text: "可口可乐", prc: 7, src: "./img/coco.jpg" },
      { text: "雪碧", prc: 7, src: "./img/spirit.jpeg" },
      { text: "芬达", prc: 7, src: "./img/fenda.jpg" },
    ],
    zhushilist: [
      { text: "滕香鸡腿堡", prc: 18, src: "./img/jituiham.jpeg" },
      { text: "奥尔良鸡腿堡", prc: 15, src: "./img/aoerliangham.jpg" },
      { text: "鸡腿堡", prc: 10, src: "./img/jituiham.jpeg" },
    ],
    xiaoshilist: [
      { text: "大薯", prc: 16, src: "./img/shutiaoL.jpg" },
      { text: "中薯", prc: 10, src: "./img/shutiaoM.jpg" },
      { text: "小薯", prc: 6, src: "./img/shutiaoS.jpeg" },
    ],
  },

  methods: {
    addgoods(item) {
      if (this.nowdingdanlist.includes(item)) {
        let index = this.nowdingdanlist.indexOf(item);

        this.nowdingdanlist[index].num++;

        this.nowdingdanlist.splice(index, 1, this.nowdingdanlist[index]);
      } else {
        item.num = 1;
        this.nowdingdanlist.push(item);
      }
    },
    add(index) {
      this.nowdingdanlist[index].num++;
      this.nowdingdanlist.splice(index, 1, this.nowdingdanlist[index]);
    },
    remove(index) {
      this.nowdingdanlist.splice(index, 1);
    },
    jian(index) {
      if (this.nowdingdanlist[index].num == 1) {
        this.nowdingdanlist.splice(index, 1);
      } else {
        this.nowdingdanlist[index].num--;
        this.nowdingdanlist.splice(index, 1, this.nowdingdanlist[index]);
      }
    },
    noworderclick() {
      //this.order = "noworder";
      this.comName = "floor-list";
      this.dingdanps = 5;
    },
    guadanclick() {
      //this.order = "guadan";
      this.comName = "";
      this.dingdanps = 75;
    },
    fukuanclick() {
      // this.order = "fukuan";
      this.comName = "";
      this.dingdanps = 135;
    },
    quxiaoclick() {
      //this.order = "quxiao";
      this.comName = "";
      this.dingdanps = 205;
    },
    commonfood() {
      this.menuorder = "commonfoodtext";
      this.chanpinps = 7;
    },
    mainmenu() {
      this.menuorder = "mainmenu";
      this.chanpinps = 277;
    },
  },
  watch: {
    nowdingdanlist: function (newval) {
      let that = this;
      this.money = 0;
      newval.forEach((item) => {
        that.money += item.num * item.prc;
      });
    },
  },
});